<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <title>登录界面</title>
    <!--必要样式-->
    <link href="/static/css/styles.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/loaders.css" rel="stylesheet" type="text/css"/>
    <link href="/static/js/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="/static/js/jquery.js"></script>
    <script type="text/javascript" src="/static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src='/static/js/stopExecutionOnTimeout.js?t=1'></script>
    <script type="text/javascript" src="/static/js/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/Particleground.js"></script>
    <script type="text/javascript" src="/static/js/Treatment.js"></script>
    <script type="text/javascript" src="/static/js/jquery.mockjax.js"></script>
</head>
<body>
<div class='login'>
    <div class='login_title'>
        <span>教育系统登录界面</span>
    </div>
    <div class='login_fields'>
        <form action="/login" method="post">
            <div class='login_fields__user'>
                <div class='icon'>
                    <img alt="" src='/static/img/user_icon_copy.png'>
                </div>
                <input name="username" placeholder='账号' maxlength="16" type='text' autocomplete="off"/>
                <div class='validation'>
                    <img alt="" src='/static/img/tick.png'>
                </div>
            </div>
            <div class='login_fields__password'>
                <div class='icon'>
                    <img alt="" src='/static/img/lock_icon_copy.png'>
                </div>
                <input name="password" placeholder='密码' maxlength="16" type='password' autocomplete="off">
                <div class='validation'>
                    <img alt="" src='/static/img/tick.png'>
                </div>
            </div>
            <div class='login_fields__password'>
                <div class='icon'>
                    <img alt="" src='/static/img/key.png'>
                </div>
                <input name="code" placeholder='验证码' maxlength="4" type='text' name="ValidateNum" autocomplete="off">
                <div class='validation' style="opacity: 1; right: -140px;top: -3px;">
                    <canvas class="J_codeimg" id="myCanvas" onclick="Code();">对不起，您的浏览器不支持canvas，请下载最新版浏览器!</canvas>
                </div>
            </div>
            <div class='login_fields__submit'>
                <input id="login_btn" type='button' value='登录'>
            </div>
        </form>
    </div>
    <div class='success'>
    </div>
</div>
<div class='authent'>
    <div class="loader" style="height: 44px;width: 44px;margin-left: 28px;">
        <div class="loader-inner ball-clip-rotate-multiple">
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <p>认证中...</p>
</div>
<div class="OverWindows"></div>
<script type="text/javascript">
    var canGetCookie = 0;//是否支持存储Cookie 0 不支持 1 支持
    var CodeVal = 0;
    Code();

    function Code() {
        if (canGetCookie == 1) {
            createCode("AdminCode");
            var AdminCode = getCookieValue("AdminCode");
            showCheck(AdminCode);
        } else {
            showCheck(createCode(""));
        }
    }

    function showCheck(a) {
        CodeVal = a;
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        ctx.clearRect(0, 0, 1000, 1000);
        ctx.font = "80px 'Hiragino Sans GB'";
        ctx.fillStyle = "#E8DFE8";
        ctx.fillText(a, 0, 100);
    }

    $(document).keypress(function (e) {
        // 回车键事件
        if (e.which == 13) {
            $('input[type="button"]').click();
        }
    });
    //粒子背景特效
    /*$('body').particleground({
        dotColor: '#E8DFE8',
        lineColor: '#133b88'
    });
    $('input[name="password"]').focus(function () {
        $(this).attr('type', 'password');
    });
    $('input[type="text"]').focus(function () {
        $(this).prev().animate({'opacity': '1'}, 200);
    });
    $('input[type="text"],input[type="password"]').blur(function () {
        $(this).prev().animate({'opacity': '.5'}, 200);
    });
    $('input[name="username"],input[name="password"]').keyup(function () {
        var Len = $(this).val().length;
        if (!$(this).val() == '' && Len >= 5) {
            $(this).next().animate({
                'opacity': '1',
                'right': '30'
            }, 200);
        } else {
            $(this).next().animate({
                'opacity': '0',
                'right': '20'
            }, 200);
        }
    });*/

    layui.use('layer', function () {
        //非空验证
        $('input[type="button"]').click(function () {
            var username = $('input[name="username"]').val();
            var password = $('input[name="password"]').val();
            var code = $('input[name="code"]').val();
            if (username == '') {
                ErroAlert('请输入您的账号');
            } else if (password == '') {
                ErroAlert('请输入密码');
            } else if (code == '') {
                ErroAlert('请输入验证码');
            } else if (code.length != 4) {
                ErroAlert('验证码长度必须为4位');
            } else {
                //登录
                var JsonData = {username: username, password: password, code: code};
                if (JsonData.code.toUpperCase() == CodeVal.toUpperCase()) {
                    //认证中..
                    $('.login').addClass('test'); //倾斜特效
                    setTimeout(function () {
                        $('.login').addClass('testtwo'); //平移特效
                    }, 1000);
                    setTimeout(function () {
                        $('.authent').show().animate({right: -320}, {
                            easing: 'easeOutQuint',
                            duration: 1000,
                            queue: false
                        });
                        $('.authent').animate({opacity: 1}, {
                            duration: 500,
                            queue: false
                        }).addClass('visible');
                    }, 00);
                    $.ajax({
                        url: '/login',
                        data: $("form").serialize(),
                        dataType: 'json',
                        type: 'post',
                        success: function (data) {
                            setTimeout(function () {
                                $('.authent').show().animate({right: 90}, {
                                    easing: 'easeOutQuint',
                                    duration: 600,
                                    queue: false
                                });
                                $('.authent').animate({opacity: 0}, {
                                    duration: 200,
                                    queue: false
                                }).addClass('visible');
                                $('.login').removeClass('testtwo'); //平移特效
                            }, 2000);
                            setTimeout(function () {
                                $('.authent').hide();
                                $('.login').removeClass('test');
                                if (data.success) {

                                    //登录成功
                                    $('.login div').fadeOut(100);
                                    $('.success').fadeIn(1000);
                                    $('.success').html("登录成功<br /><br />欢迎回来");
                                    setTimeout(function () {
                                        window.parent.location.href = "/main"
                                    }, 1000);
                                } else {
                                    ErroAlert(data.msg);
                                }
                            }, 2400);
                        }
                    });
                } else {
                    ErroAlert("验证码错误");
                }
            }
        })
    });
</script>
</body>
</html>
